﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ATW.MT.BUS;
using ATW.MT.CommonClass;
using System.Text;

namespace ATW.MT.BaseManage
{
    public partial class ConfigManage : CommonPage
    {
        bus_D_Foundation Foundation = new bus_D_Foundation();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            try
            {
                string name = txtTypeName.Value.Trim();
                DataTable dt = Foundation.Foundation(name, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                if (dt != null && dt.Rows.Count > 0)
                {
                    AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalpagesize"]);
                }
                else
                {
                    AspNetPager1.RecordCount = 0;
                }
                rpList.DataSource = dt;
                rpList.DataBind();
            }
            catch (Exception ex)
            {

            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }

        protected void AspNetPager1_pageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        //修改确认
        protected void btnModify_Click(object sender, EventArgs e)
        {
            try
            {
                string strDFID = DFID.Value;
                string strType = dfType.Value;
                string strValue = dfValue.Value;


                int result = Foundation.ModifyFoundation(strType, strValue, strDFID);
                if (result > 0)
                {
                    ShowMsgTips("修改成功", 1);
                    BindData();
                }
                else
                {
                    ShowMsgTips("修改失败", 2);
                    return;
                }
            }
            catch (Exception ex)
            {
                //return "操作失败:" + ex.Message;
            }
        }
        //修改
        protected void lbnModify_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            string strId = lbn.CommandArgument;
            try
            {
                DataTable dtResult = Foundation.SelectFoundation(strId);

                if (dtResult.Rows.Count > 0)
                {
                    this.DFID.Value = dtResult.Rows[0]["DFID"].ToString();
                    this.dfType.Value = dtResult.Rows[0]["dfType"].ToString();
                    this.dfValue.Value = dtResult.Rows[0]["dfValue"].ToString();
                }



                StringBuilder sb = new StringBuilder();

                sb.Append("<script language='javascript'>");

                sb.Append("var divAdd = new jSharp.popUpDiv('divAdd');function Show(){divAdd.Show()} Show(); $('#hideAdd').click(function () {divAdd.Close();})");

                sb.Append("</script>");

                ClientScript.RegisterStartupScript(this.GetType(), "LoadPicScript", sb.ToString());

            }
            catch (Exception ex)
            {

            }
        }

        private void writeRes(string s)
        {
            Response.Clear();
            Response.Write(s);
            Response.End();
        }

        //清空控件
        private void Clear()
        {
            DFID.Value = "";
            dfType.Value = "";
            dfValue.Value = "";
        }
    }
}